﻿using System;
using System.Collections.Generic;
using System.Windows.Controls;
using Flexible.Implementions.Bases;
using Flexible.Interfaces;

namespace Flexible.Wpf
{
    class FileListPlugin : PluginBase
    {
        ListView list;
        StackPanel panel;

        public override void Enable(IPluginActivateContext context)
        {
            FolderViewPlugin folder = context.GetRequirement("Flexible.Wpf.FolderView") as FolderViewPlugin;
            TreeView folderTree = folder.FolderTree;
            Panel parent = folderTree.Parent as Panel;

            int index = parent.Children.IndexOf(folder.FolderTree);
            parent.Children.RemoveAt(index);

            panel = new StackPanel();
            panel.Orientation = Orientation.Horizontal;
            panel.Children.Add(folderTree);

            list = new ListView();
            list.Items.Add("Files listing here...");
            panel.Children.Add(list);

            parent.Children.Insert(index, panel);
        }

        public override void Disable(IPluginActivateContext context)
        {
            Panel parent = panel.Parent as Panel;
            int index = parent.Children.IndexOf(panel);
            parent.Children.RemoveAt(index);

            FolderViewPlugin folder = context.GetRequirement("Flexible.Wpf.FolderView") as FolderViewPlugin;
            TreeView folderTree = folder.FolderTree;

            panel.Children.Remove(folderTree);
            parent.Children.Insert(index, folderTree);
        }

        public override IEnumerable<IPluginQuery> Requirements
        {
            get
            {
                yield return new PluginQuery("Flexible.Wpf.FolderView", new Version(1, 0, 0, 0));
            }
        }

        #region Info
        public override string Name
        {
            get { return "File List"; }
        }

        public override string Description
        {
            get { return "Displays the files in current directory."; }
        }

        public override string Author
        {
            get { return "deerchao"; }
        }

        public override DateTime ReleaseTime
        {
            get { return new DateTime(2008, 4, 10); }
        }

        public override string Id
        {
            get { return "Flexible.Wpf.FileList"; }
        }

        public override Version Version
        {
            get { return new Version(1, 0, 0, 0); }
        }

        public override Version CompatibleVersion
        {
            get { return new Version(1, 0, 0, 0); }
        }
        #endregion
    }
}
